/******************************************************************************
 * * setting_wlan.c - implementation of setting wlan functions
 *
 * *(C) Copyright 2020 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "lv_conf.h"

#if USE_LV_WLAN != 0

#include "setting_global.h"
#include "../../framework/message/phone_msg_handle.h"

static VOID Display_Setting_Wlan_Info_Chg_Cb(bool Is_Periodic_Scan);
static VOID Display_Setting_Wlan(VOID);
static VOID Display_Setting_Wlan_Refreshing_Anim_Func(lv_anim_t *Anim);
static VOID Display_Setting_Wlan_Sw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event);
static VOID Display_Setting_Wlan_Refresh_Ui(BOOL SelOpeningBtn);
static VOID Display_Setting_Wlan_Saved_Nw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event);

VOID Setting_Wlan_Init(VOID)
{
    hal_wlan_info_chg_cb_register(Display_Setting_Wlan_Info_Chg_Cb);
    hal_wlan_init(false);
}

VOID Display_Setting_Wlan_Cb(lv_obj_t * Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    Display_Setting_Wlan();
}

VOID Mmi_Wlan_Refresh_Ind(VOID)
{
    Display_Setting_Wlan_Refresh_Ui(FALSE); // not jump to top
}

VOID Mmi_Wlan_Periodic_Scan_Start_Ind(VOID)
{
    if (ACT_ID_SETTING_WLAN != Nav_Get_Top())
    {
        return;
    }

    UI_Wlan_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN);
    if(NULL == Desc) return;

    if(NULL == Desc->RefreshImg) {
        printf("%s: warning, refresh img is NULL\n", __FUNCTION__);
        return;
    }

    printf("%s\n", __FUNCTION__);

    lv_obj_t * Btn = lv_obj_get_parent(lv_obj_get_parent(Desc->RefreshImg));
    if(UI_WLAN_BTN_TYPE_REFRESH == UI_Get_User_Num(Btn)) {
        UI_Wlan_Play_Refreshing_Anim(Desc->RefreshImg,
                                     SYMBOL_REFRESH_2,
                                     Display_Setting_Wlan_Refreshing_Anim_Func);
        UI_Set_User_Num(Btn, UI_WLAN_BTN_TYPE_REFRESHING);
    }
}

static VOID Setting_Wlan_Get_Security_Txt(HAL_WLAN_SECURITY_T Security, UINT8 TxtLen, INT8 *Txt)
{
    if ((NULL == Txt) || (0 == TxtLen))
    {
        printf("%s: warning, txt is NULL\n", __FUNCTION__);
        return;
    }

    switch (Security)
    {
    case HAL_WLAN_SECURITY_OPEN:
        strncpy(Txt, lv_lang_get_text(PHONE_TEXT_ID_NONE), TxtLen);
        break;
    case HAL_WLAN_SECURITY_WEP:
        strncpy(Txt, "WEB", TxtLen);
        break;
    case HAL_WLAN_SECURITY_WPA:
        strncpy(Txt, "WPA", TxtLen);
        break;
    case HAL_WLAN_SECURITY_WPA2:
        strncpy(Txt, "WPA2", TxtLen);
        break;
    case HAL_WLAN_SECURITY_WPA_WPA2:
        strncpy(Txt, "WPA/WPA2", TxtLen);
        break;
    default:
        printf("%s: warning, wrong security %d\n", __FUNCTION__, Security);
        break;
    }
}

static VOID Setting_Wlan_Get_Signal_Txt(UINT8 Power, UINT8 TxtLen, INT8 *Txt)
{
    if ((NULL == Txt) || (0 == TxtLen))
    {
        printf("%s: warning, txt is NULL\n", __FUNCTION__);
        return;
    }

    if (HAL_WLAN_SIGNAL_STRENGTH_EXCELLENT < Power)
    {
        strncpy(Txt, lv_lang_get_text(PHONE_TEXT_ID_EXCELLENT), TxtLen);
    }
    else if (HAL_WLAN_SIGNAL_STRENGTH_GOOD < Power)
    {
        strncpy(Txt, lv_lang_get_text(PHONE_TEXT_ID_GOOD), TxtLen);
    }
    else if (HAL_WLAN_SIGNAL_STRENGTH_FAIR < Power)
    {
        strncpy(Txt, lv_lang_get_text(PHONE_TEXT_ID_FAIR), TxtLen);
    }
    else if (HAL_WLAN_SIGNAL_STRENGTH_POOR < Power)
    {
        strncpy(Txt, lv_lang_get_text(PHONE_TEXT_ID_POOR), TxtLen);
    }
    else
    {
        strncpy(Txt, lv_lang_get_text(PHONE_TEXT_ID_NONE), TxtLen);
    }
}

static UINT8 Display_Setting_Wlan_Status_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta,
                                                UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        switch (Key_Val)
        {
        case KEY_END:
            Nav_Home(ACT_ID_ANY);
            break;

        default:
            break;
        } /* switch */
    }

    return(1);
}

static VOID Display_Setting_Wlan_Status_Timer_Cb(lv_task_t *Task)
{
    Nav_Back(ACT_ID_SETTING_WLAN_STATUS);
}

static VOID Display_Setting_Wlan_Status_OnCreate(VOID *Param)
{
    UI_Status_Desc_t *Desc = (UI_Status_Desc_t *)Param;
    lv_task_t *Task = lv_task_create(Display_Setting_Wlan_Status_Timer_Cb, 2000,
                                     LV_TASK_PRIO_HIGH, NULL);
    lv_task_once(Task);
    UI_Set_User_Ptr(Desc->ContLabel.Label, Task);
}

static VOID Display_Setting_Wlan_Status_OnSave(VOID *Param)
{
    UI_Status_Desc_t *Desc = (UI_Status_Desc_t *)Param;
    lv_task_t *Task = (lv_task_t *)UI_Get_User_Ptr(Desc->ContLabel.Label);
    lv_task_del(Task);
    Nav_Back(ACT_ID_SETTING_WLAN_STATUS);
}

static VOID Display_Setting_Wlan_Status_OnDestroy(VOID *Param)
{
    Hal_Mem_Free(Param);
}

static VOID Display_Setting_Wlan_Status(UINT16 TxtId)
{
    UI_Status_Desc_t *Desc;
    Nav_Func_List_t  FuncList;

    Desc = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Status_Desc_t));

    Desc->ContLabel.TxtId      = TxtId;
    Desc->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    Desc->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    Desc->ContImg.Img  = LV_SYMBOL_WARNING;
    Desc->ContImgAlign = LV_ALIGN_IN_TOP_RIGHT;

    Desc->KeyFunc = Display_Setting_Wlan_Status_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow      = UI_Status_Create;
    FuncList.OnCreate    = Display_Setting_Wlan_Status_OnCreate;
    FuncList.OnSaveState = Display_Setting_Wlan_Status_OnSave;
    FuncList.OnDestroy   = Display_Setting_Wlan_Status_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_STATUS, &FuncList, Desc);
}

static UINT8 Display_Setting_Wlan_List_Com_KeyCb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    if (KEY_RELEASED == Key_Sta)
    {
        UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(Nav_Get_Top());

        if ((KEY_UP == Key_Val)
            || (KEY_DOWN == Key_Val)
            || (KEY_LEFT == Key_Val)
            || (KEY_RIGHT == Key_Val))
        {
            if (1 < Desc->BtnCnt)
            {
                UINT8 OldIndex = Desc->Index;
                if ((KEY_UP == Key_Val) || (KEY_LEFT == Key_Val))
                {
                    do
                    {
                        Desc->Index += Desc->BtnCnt;
                        Desc->Index--;
                        Desc->Index = Desc->Index % Desc->BtnCnt;
                        if (FALSE == lv_obj_get_hidden(Desc->BtnList[Desc->Index].Btn))
                        {
                            lv_list_focus_btn(Desc->List, Desc->BtnList[Desc->Index].Btn);
                            break;
                        }
                    }
                    while (OldIndex != Desc->Index);
                }
                else
                {
                    do
                    {
                        Desc->Index++;
                        Desc->Index = Desc->Index % Desc->BtnCnt;
                        if (FALSE == lv_obj_get_hidden(Desc->BtnList[Desc->Index].Btn))
                        {
                            lv_list_focus_btn(Desc->List, Desc->BtnList[Desc->Index].Btn);
                            break;
                        }
                    }
                    while (OldIndex != Desc->Index);
                }
            }
            return(1);
        }
        else if (KEY_OK == Key_Val)
        {
            if(Desc->BtnList[Desc->Index].RelFunc)
            {
                Desc->BtnList[Desc->Index].RelFunc(Desc->BtnList[Desc->Index].Btn,
                                                   LV_EVENT_CLICKED);
            }
            return(1);
        }
        else if (KEY_SOFTLEFT == Key_Val)
        {
            if (Desc->BtnBar.ButtonL.Valid)
            {
                if (Desc->BtnBar.ButtonL.ReleaseFun)
                {
                    Desc->BtnBar.ButtonL.ReleaseFun(Desc->BtnBar.ButtonL.Button, LV_EVENT_CLICKED);
                }
            }            
            return(1);
        }
        else if (KEY_SOFTRIGHT == Key_Val)
        {
            Nav_Back(ACT_ID_ANY);
            return(1);
        }
        else if (KEY_END == Key_Val)
        {
            Nav_Home(ACT_ID_ANY);
            return(1);
        }
    }

    return(0);
}

static VOID Display_Setting_Wlan_Login_OnCreate(VOID *Param)
{
    UI_Wlan_List_Desc_t *Desc = (UI_Wlan_List_Desc_t *)Param;
    lv_obj_t *Label;
    lv_obj_t *Ta;
    hal_wlan_ap_info_t *Ap = (hal_wlan_ap_info_t *)Desc->Param;
    INT8 Txt[20] = {};
    UINT8 i;

    lv_label_set_text(Desc->TitleBar.Label, Ap->ssid);

    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if (PHONE_TEXT_ID_SECURITY == Desc->BtnList[i].Label.TxtId)
        {
            Label = Desc->BtnList[i].Label.Label;
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, ":\n");
            Setting_Wlan_Get_Security_Txt(Ap->security, 20, Txt);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, Txt);

            Label = lv_obj_get_child_back(lv_obj_get_parent(Label), Label);
            lv_label_set_text_id(Label, PHONE_TEXT_ID_SIGNAL_STRENGTH);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, ":\n");
            Hal_Mem_Set(Txt, 0, 20);
            Setting_Wlan_Get_Signal_Txt(Ap->power, 20, Txt);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, Txt);
            break;
        }
    }

    if (HAL_WLAN_SECURITY_OPEN != Ap->security)
    {
        Ta = Desc->BtnList[1].u.Ta.TextArea;
        lv_textarea_set_pwd_mode(Ta, TRUE);
        lv_textarea_set_max_length(Ta, HAL_WLAN_MAX_PWD_LEN);
        if (Desc->BtnList[1].u.Ta.TaTxt)
        {
            Hal_Mem_Free(Desc->BtnList[1].u.Ta.TaTxt);
            Desc->BtnList[1].u.Ta.TaTxt = NULL;
        }
    }
}

static VOID Display_Setting_Wlan_List_Com_OnDestroy(VOID *Param)
{
    UI_Wlan_List_Desc_t *Desc = (UI_Wlan_List_Desc_t *)Param;
    UINT8 i;
    if (Desc->Param)
    {
        Hal_Mem_Free(Desc->Param);
    }
    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if (UI_BASE_OBJ_TA == Desc->BtnList[i].Choise)
        {
            if(Desc->BtnList[i].u.Ta.TaTxt)
            {
                Hal_Mem_Free(Desc->BtnList[i].u.Ta.TaTxt);
            }
        }
    }
    if (Desc->BtnList)
    {
        Hal_Mem_Free(Desc->BtnList);
    }
    Hal_Mem_Free(Param);
}

static VOID Display_Setting_Wlan_List_Com_OnSave(VOID *Param)
{
    UI_Wlan_List_Desc_t *Desc = (UI_Wlan_List_Desc_t *)Param;
    UINT8 i;
    INT8 *Txt;
    UINT8 Len;
    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if ((PHONE_TEXT_ID_SSID == Desc->BtnList[i].Label.TxtId)
            || (PHONE_TEXT_ID_PWD == Desc->BtnList[i].Label.TxtId))
        {
            Txt = (INT8 *)lv_textarea_get_text(Desc->BtnList[i].u.Ta.TextArea);
            Len = strlen(Txt);
            if(0 < Len)
            {
                Desc->BtnList[i].u.Ta.TaTxt = Hal_Mem_Alloc(Len + 1);
                Hal_Mem_Copy(Desc->BtnList[i].u.Ta.TaTxt, Txt, Len + 1);
            }
        }
    }
}

static UINT8 Display_Setting_WLan_Input_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta,
                                               UI_KEY_VALUE Key_Val)
{
    UINT8                             Ret  = 1;
    INT8                              Char = 0;
    UI_Normal_NoTitle_Label_Ta_Desc_t *Desc;
    UI_Wlan_List_Desc_t               *ListDesc;
    lv_obj_t                          *Ta;
    lv_obj_t                          *Label;
    UINT8                             Len;
    UINT8                             Max;
    INT8                              Number[3] = {0};
    UINT16                            PrevActId;
    INT8                              *TaTxt;

    if (KEY_RELEASED == Key_Sta)
    {
        Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_INPUT);

        switch (Key_Val)
        {
        case KEY_SOFTRIGHT:
            if (PHONE_TEXT_ID_BACK == Desc->ButtonCont.ButtonR.TxtId)
            {
                Nav_Back(ACT_ID_ANY);
            }
            else // clear
            {
                Ta = Desc->ContTa.TextArea;
                if (0 == lv_textarea_get_cursor_pos(Ta))
                {
                    /*do nothing if cursor is at the head of text*/
                    break;
                }

                lv_textarea_del_char(Ta);
                Len = strlen(lv_textarea_get_text(Ta));
                if (0 == Len) // no text on TA
                {
                    Desc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
                    Label = lv_obj_get_child(Desc->ButtonCont.ButtonR.Button, NULL);
                    lv_label_set_text_id(Label, PHONE_TEXT_ID_BACK);
                }
                Max = lv_textarea_get_max_length(Ta);
                if (Max < Len)
                {
                    printf("%s: warning, max %d < len %d\n", __FUNCTION__, Max, Len);
                    break;
                }
                snprintf(Number, 3, "%d", Max - Len);
                lv_label_set_text(Desc->ContLabelTr.Label, Number);
            }
            break;

        case KEY_SOFTLEFT:
            if (FALSE == Desc->ButtonCont.ButtonL.Valid)
            {
                break;
            }

            Ta = Desc->ContTa.TextArea;
            Label = lv_obj_get_child(Desc->ButtonCont.ButtonL.Button, NULL);
            if (PHONE_TEXT_ID_SHOW == Desc->ButtonCont.ButtonL.TxtId)
            {
                Desc->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_HIDE;
                lv_textarea_set_pwd_mode(Ta, FALSE);
            }
            else
            {
                Desc->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_SHOW;
                lv_textarea_set_pwd_mode(Ta, TRUE);
            }
            lv_label_set_text_id(Label, Desc->ButtonCont.ButtonL.TxtId);
            break;

        case KEY_HASH: // single mode for ime, only support english and number mode
            if (LV_IME_MODE_ENGLISH == Ime_Get_Mode())
            {
                Ime_Set_SingleMode(FALSE);
                Ime_Signal(KEY_HASH);
                Ime_Set_SingleMode(TRUE);
            }
            else if (LV_IME_MODE_NUM == Ime_Get_Mode())
            {
                Ime_Set_SingleMode(FALSE);
                Ime_Set_Mode(LV_IME_MODE_ENGLISH);
                Ime_Set_SingleMode(TRUE);
            }
            else
            {
                printf("%s: warning, wrong ime mode %d\n", __FUNCTION__, Ime_Get_Mode());
            }
            break;

        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_ASTERISK:
            if (KEY_ASTERISK == Key_Val)
            {
                Char = '*';
            }
            else
            {
                Char = Key_Val - KEY_0 + '0';
            }
            Ta = Desc->ContTa.TextArea;
            Len = strlen(lv_textarea_get_text(Ta));
            Max = lv_textarea_get_max_length(Ta);
            if (Len < Max)
            {
                lv_textarea_add_char(Ta, Char);
                if (0 == Len) // no text on TA before input
                {
                    Desc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;
                    Label = lv_obj_get_child(Desc->ButtonCont.ButtonR.Button, NULL);
                    lv_label_set_text_id(Label, Desc->ButtonCont.ButtonR.TxtId);
                }
                Len = strlen(lv_textarea_get_text(Ta));
                snprintf(Number, 3, "%d", Max - Len);
                lv_label_set_text(Desc->ContLabelTr.Label, Number);
            }
            break;

        case KEY_UP:
        case KEY_DOWN:
        case KEY_LEFT:
        case KEY_RIGHT:
            Ret = 0;
            break;

        case KEY_OK:
            Ta = Desc->ContTa.TextArea;
            TaTxt = (INT8 *)lv_textarea_get_text(Ta);
            Len = strlen(TaTxt);
            PrevActId = Nav_Get_Prev(ACT_ID_SETTING_WLAN_INPUT);
            if (ACT_ID_SETTING_WLAN_SAVED_AP == PrevActId)
            {
                if (HAL_WLAN_MIN_PWD_LEN > Len)
                {
                    Display_Setting_Wlan_Status(PHONE_TEXT_ID_MIN_PWD_LEN_IS_8);
                }
                else
                {
                    ListDesc = Nav_Get_Param(PrevActId);
                    if(hal_wlan_ui_open_ap((hal_wlan_ap_info_t *)ListDesc->Param, TaTxt)) {
                        Display_Setting_Wlan_Refresh_Ui(TRUE);
                    }
                    Nav_Forward(ACT_ID_SETTING_WLAN_INPUT, ACT_ID_SETTING_WLAN, NULL, NULL);
                }
            }
            else
            {
                ListDesc = Nav_Get_Param(PrevActId);
                if (ListDesc->BtnList[ListDesc->Index].u.Ta.TaTxt)
                {
                    Hal_Mem_Free(ListDesc->BtnList[ListDesc->Index].u.Ta.TaTxt);
                }
                if (0 < Len)
                {
                    ListDesc->BtnList[ListDesc->Index].u.Ta.TaTxt = Hal_Mem_Alloc(Len + 1);
                    Hal_Mem_Copy(ListDesc->BtnList[ListDesc->Index].u.Ta.TaTxt,
                                 lv_textarea_get_text(Ta), Len + 1);
                }
                else
                {
                    ListDesc->BtnList[ListDesc->Index].u.Ta.TaTxt = NULL;
                }
                Nav_Back(ACT_ID_ANY);
            }
            break;

        case KEY_END:
            Nav_Home(ACT_ID_ANY);
            break;

        default:
            break;
        } /* switch */
    }
    return(Ret);
}

static VOID Display_Setting_WLan_Input_Cb(UINT8 Len)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_INPUT);
    UINT8                             TxtLen = strlen(lv_textarea_get_text(Desc->ContTa.TextArea));
    INT8                              Text[3];
    UINT32                            Max = lv_textarea_get_max_length(Desc->ContTa.TextArea);

    if (Max < TxtLen)
    {
        printf("%s: warning, txt len %d > max %d\n", __FUNCTION__, TxtLen, Max);
        return;
    }

    sprintf(Text, "%d", Max - TxtLen);
    lv_label_set_text(Desc->ContLabelTr.Label, Text);

    if (PHONE_TEXT_ID_BACK == Desc->ButtonCont.ButtonR.TxtId)
    {
        Desc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;
        lv_label_set_text_id(lv_obj_get_child(Desc->ButtonCont.ButtonR.Button, NULL),
                             Desc->ButtonCont.ButtonR.TxtId);
    }
}

static VOID Display_Setting_WLan_Input_OnCreate(VOID *Param)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *Desc  = (UI_Normal_NoTitle_Label_Ta_Desc_t *)Param;
    lv_obj_t                          *Label = Desc->ContLabelTr.Label;
    lv_obj_t                          *Ta    = Desc->ContTa.TextArea;
    const INT8                        *TaTxt = lv_textarea_get_text(Ta);
    INT8                              Text[3];
    UINT32                            Max = 0;
    UINT8                             Len = strlen(TaTxt);
    printf("%s: tatxtlen %d, txt %s\n", __FUNCTION__, Len, TaTxt);
    if (PHONE_TEXT_ID_SSID == Desc->ContLabel.TxtId)
    {
        Max = HAL_WLAN_MAX_SSID_LEN;
    }
    else if (PHONE_TEXT_ID_PWD == Desc->ContLabel.TxtId)
    {
        Max = HAL_WLAN_MAX_PWD_LEN;

        Ime_Set_Mode(LV_IME_MODE_ENGLISH);
        Ime_Set_SingleMode(TRUE);

        if (PHONE_TEXT_ID_SHOW == Desc->ButtonCont.ButtonL.TxtId)
        {
            lv_textarea_set_pwd_mode(Ta, TRUE);
        }
    }
    else
    {
        printf("%s: warning, wrong txtid %d\n", __FUNCTION__, Desc->ContLabel.TxtId);
        return;
    }
    if (Max < Len)
    {
        printf("%s: warning, txt len %d > max %d\n", __FUNCTION__, Len, Max);
        return;
    }
    Ime_Set_GetCharLen_Func(Display_Setting_WLan_Input_Cb);

    sprintf(Text, "%d", Max - Len);
    lv_label_set_text(Label, Text);
    lv_obj_align(Label, lv_obj_get_parent(Label), LV_ALIGN_IN_TOP_RIGHT,
                 0, lv_obj_get_y(Label));

    lv_textarea_set_max_length(Ta, Max);

    if (Desc->ContTa.TaTxt)
    {
        Hal_Mem_Free(Desc->ContTa.TaTxt);
        Desc->ContTa.TaTxt = NULL;
    }
}

static VOID Display_Setting_WLan_Input_OnSaveState(VOID *Param)
{
    UI_Text_Area_Desc_t *ContTa = &(((UI_Normal_NoTitle_Label_Ta_Desc_t *)Param)->ContTa);
    const INT8          *Text = lv_textarea_get_text(ContTa->TextArea);
    UINT8               Len = strlen(Text);

    if (0 < Len)
    {
        Len++;
        ContTa->TaTxt = (INT8 *)Hal_Mem_Alloc(Len);
        Hal_Mem_Copy(ContTa->TaTxt, (INT8 *)Text, Len);
    }
}

static VOID Display_Setting_WLan_Input_OnDestroy(VOID *Param)
{
    UI_Text_Area_Desc_t *ContTa = &(((UI_Normal_NoTitle_Label_Ta_Desc_t *)Param)->ContTa);

    if (ContTa->TaTxt)
    {
        Hal_Mem_Free(ContTa->TaTxt);
    }
    Hal_Mem_Free(Param);
}

static VOID Display_Setting_WLan_Input(const INT8 *Txt, UINT16 TitleTxtId)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *Desc;
    Nav_Func_List_t                   FuncList;
    UINT8                             TxtLen = 0;

    printf("%s: txt id %d, txt %s\n", __FUNCTION__, TitleTxtId, Txt);

    Desc = Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));

    Desc->ContLabelTl.TxtId       = LV_LANG_TXT_ID_NONE;
    Desc->ContLabelTl.TxtAlign    = LV_LABEL_ALIGN_LEFT;
    Desc->ContLabelTl.LabelAlign  = LV_ALIGN_IN_TOP_LEFT;
    Desc->ContLabelTl.SymbolId    = LV_SYMBOL_EDIT;
    Desc->ContLabelTl.SymbolAlign = LV_LABEL_ALIGN_LEFT;

    Desc->ContLabelTr.TxtId      = LV_LANG_TXT_ID_NONE;
    Desc->ContLabelTr.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    Desc->ContLabelTr.LabelAlign = LV_ALIGN_IN_TOP_RIGHT;

    Desc->ContLabel.TxtId      = TitleTxtId;
    Desc->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    Desc->ContLabel.LabelAlign = LV_ALIGN_IN_LEFT_MID;

    if (Txt)
    {
        TxtLen = strlen(Txt);
    }
    if (0 < TxtLen)
    {
        Desc->ContTa.TaTxt = Hal_Mem_Alloc(TxtLen + 1);
        Hal_Mem_Copy(Desc->ContTa.TaTxt, Txt, TxtLen + 1);
    }
    Desc->ContTa.TaCursorHide = TRUE;
    Desc->ContTa.TaAlign      = LV_ALIGN_IN_BOTTOM_LEFT;

    if (PHONE_TEXT_ID_PWD == TitleTxtId)
    {
        Desc->ButtonCont.ButtonL.Valid = TRUE;
        Desc->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_SHOW; // password mode
    }
    else
    {
        Desc->ButtonCont.ButtonL.Valid = FALSE;
    }
    Desc->ButtonCont.ButtonM.Valid = TRUE;
    Desc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    Desc->ButtonCont.ButtonR.Valid = TRUE;
    if (0 == TxtLen)
    {
        Desc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    }
    else
    {
        
        Desc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;
    }

    Desc->KeyFunc = Display_Setting_WLan_Input_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_NoTitle_Label_Ta_Create;
    FuncList.OnCreate       = Display_Setting_WLan_Input_OnCreate;
    FuncList.OnRestoreState = Display_Setting_WLan_Input_OnCreate;
    FuncList.OnSaveState    = Display_Setting_WLan_Input_OnSaveState;
    FuncList.OnDestroy      = Display_Setting_WLan_Input_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_INPUT, &FuncList, Desc);
}

static VOID Display_Setting_WLan_List_Input_Btn_Com_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    printf("%s\n", __FUNCTION__);
    lv_obj_t *Ta = lv_obj_get_child(Btn, NULL);
    lv_obj_t *Label = lv_obj_get_child_back(Btn, NULL);
    Display_Setting_WLan_Input(lv_textarea_get_text(Ta), lv_label_get_text_id(Label));
}

static VOID Display_Setting_WLan_Login_Conn_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_LOGIN);
    hal_wlan_ap_info_t *Ap = (hal_wlan_ap_info_t *)Desc->Param;
    INT8 *Pwd = NULL;
    UINT8 i;
    if (HAL_WLAN_SECURITY_OPEN != Ap->security)
    {
        for (i = 0;i < Desc->BtnCnt;i++)
        {
            if (PHONE_TEXT_ID_PWD == Desc->BtnList[i].Label.TxtId)
            {
                Pwd = (INT8 *)lv_textarea_get_text(Desc->BtnList[i].u.Ta.TextArea);
                if (HAL_WLAN_MIN_PWD_LEN > strlen(Pwd))
                {
                    Display_Setting_Wlan_Status(PHONE_TEXT_ID_MIN_PWD_LEN_IS_8);
                    return;
                }
                break;
            }
        }
    }
    if (hal_wlan_ui_open_ap(Ap, Pwd))
    {
        Display_Setting_Wlan_Refresh_Ui(TRUE);
    }
    Nav_Back(ACT_ID_ANY);
}

/**
 * Display Setting_Wlan_Login
 * param (in) Ap:hal_wlan_ap_info_t *
 * return VOID
 */
static VOID Display_Setting_WLan_Login(hal_wlan_ap_info_t *Ap)
{
    UI_Wlan_List_Desc_t *Desc = NULL;
    Nav_Func_List_t     FuncList;
    UINT32              Size;
    UINT8               i = 0;

    Desc = Hal_Mem_Alloc(sizeof(UI_Wlan_List_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Wlan_List_Desc_t));

    Desc->TitleBar.TxtId = LV_LANG_TXT_ID_NONE;
    Desc->TitleBar.TxtAlign = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_CENTER;
    
    Desc->Param = Hal_Mem_Alloc(sizeof(hal_wlan_ap_info_t));
    Hal_Mem_Copy(Desc->Param, Ap, sizeof(hal_wlan_ap_info_t));

    Desc->BtnCnt = 2; // ap information & connect
    if (HAL_WLAN_SECURITY_OPEN != Ap->security)
    {
        Desc->BtnCnt++; // password
    }
    Size = sizeof(UI_Wlan_Btn_Base_Desc_t) * Desc->BtnCnt;
    Desc->BtnList = Hal_Mem_Alloc(Size);
    Hal_Mem_Set(Desc->BtnList, 0, Size);

    Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_SECURITY;
    Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[i].Choise = UI_BASE_OBJ_LABEL;
    Desc->BtnList[i++].u.LabelNum = 2; // security & signal

    if (HAL_WLAN_SECURITY_OPEN != Ap->security)
    {
        Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_PWD;
        Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
        Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        Desc->BtnList[i].Choise = UI_BASE_OBJ_TA;
        Desc->BtnList[i].u.Ta.TaCursorHide = TRUE;
        Desc->BtnList[i++].RelFunc = Display_Setting_WLan_List_Input_Btn_Com_Func;
    }

    Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_CONNECT;
    Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[i].Choise = UI_BASE_OBJ_NULL;
    Desc->BtnList[i].RelFunc = Display_Setting_WLan_Login_Conn_Btn_Click_Func;

    Desc->BtnBar.ButtonL.Valid = FALSE;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_List_Com_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Wlan_List_Create;
    FuncList.OnCreate       = Display_Setting_Wlan_Login_OnCreate;
    FuncList.OnRestoreState = Display_Setting_Wlan_Login_OnCreate;
    FuncList.OnSaveState    = Display_Setting_Wlan_List_Com_OnSave;
    FuncList.OnDestroy      = Display_Setting_Wlan_List_Com_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_LOGIN, &FuncList, (VOID *)Desc);
}

static VOID *Display_Setting_Wlan_Get_Signal_Src(UINT8 Power)
{
    if(HAL_WLAN_SIGNAL_STRENGTH_EXCELLENT < Power) {
        return (VOID *)(SYMBOL_WIFI_FULL);
    } else if(HAL_WLAN_SIGNAL_STRENGTH_GOOD < Power) {
        return (VOID *)(SYMBOL_WIFI_HIGH);
    } else if(HAL_WLAN_SIGNAL_STRENGTH_FAIR < Power) {
        return (VOID *)(SYMBOL_WIFI_MID);
    } else if(HAL_WLAN_SIGNAL_STRENGTH_POOR < Power) {
        return (VOID *)(SYMBOL_WIFI_LOW);
    } else {
        printf("%s: warning, no signal\n", __FUNCTION__);
        return (VOID *)(SYMBOL_WIFI_LOW);
    }
}

static lv_obj_t *Display_Setting_Wlan_Get_Focus_Btn(UI_Wlan_Desc_t *Desc)
{
    lv_obj_t *Scrl = lv_page_get_scrl(Desc->List);
    lv_obj_t *Btn = lv_obj_get_child_back(Scrl, NULL);
    UINT32 i = 0;

    while (Btn)
    {
        if (Desc->Index == i)
        {
            break;
        }
        i++;
        Btn = lv_obj_get_child_back(Scrl, Btn);
    }
    if (NULL == Btn)
    {
        printf("%s: not find btn, index %d, total %d\n", __FUNCTION__, Desc->Index, i);
    }

    return(Btn);
}

static VOID Display_Setting_Wlan_Refreshing_Anim_Func(lv_anim_t *Anim)
{
    lv_obj_t * Img = (lv_obj_t *)Anim->var;
    UINT8 Step = UI_Get_User_Num(Img);
    if(1 == Step) {
        lv_img_set_src(Img, SYMBOL_REFRESH_2);
        UI_Set_User_Num(Img, 2);
    } else if(2 == Step) {
        lv_img_set_src(Img, SYMBOL_REFRESH_1);
        UI_Set_User_Num(Img, 1);
    } else {
        printf("%s: warning, wrong step %d\n", __FUNCTION__, Step);
    }
}

static VOID Display_Setting_Wlan_Saved_Ap_Del_Nw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SAVED_AP);
    hal_wlan_ap_info_t *Ap = (hal_wlan_ap_info_t *)Desc->Param;
    if (hal_wlan_ui_del_saved_nw(Ap->ssid, Ap->security))
    {
        Display_Setting_Wlan_Refresh_Ui(FALSE);
    }
    Nav_Back(ACT_ID_ANY);
}

static VOID Display_Setting_Wlan_Saved_Ap_Mod_Pwd_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    Display_Setting_WLan_Input(NULL, PHONE_TEXT_ID_PWD);
}

static VOID Display_Setting_Wlan_Saved_Ap_Conn_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SAVED_AP);
    if(hal_wlan_ui_open_ap((hal_wlan_ap_info_t *)Desc->Param, NULL)) {
        Display_Setting_Wlan_Refresh_Ui(TRUE);
    }
    Nav_Back(ACT_ID_ANY);
}

static VOID Display_Setting_Wlan_Saved_Ap_OnCreate(VOID *Param)
{
    UI_Wlan_List_Desc_t *Desc = (UI_Wlan_List_Desc_t *)Param;
    lv_obj_t *Label;
    hal_wlan_ap_info_t *Ap = (hal_wlan_ap_info_t *)Desc->Param;
    INT8 Txt[20] = {};
    UINT8 i;

    lv_label_set_text(Desc->TitleBar.Label, Ap->ssid);

    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if (PHONE_TEXT_ID_STATUS_INFO == Desc->BtnList[i].Label.TxtId)
        {
            Label = Desc->BtnList[i].Label.Label;
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, ":\n");
            if (HAL_WLAN_AP_STATE_ACT == Ap->state)
            {
                lv_label_ins_text(Label, LV_LABEL_POS_LAST, lv_lang_get_text(PHONE_TEXT_ID_CONNECTED));
            }
            else
            {
                lv_label_ins_text(Label, LV_LABEL_POS_LAST, lv_lang_get_text(PHONE_TEXT_ID_NO_CONNECTION));
            }

            Label = lv_obj_get_child_back(lv_obj_get_parent(Label), Label);
            lv_label_set_text_id(Label, PHONE_TEXT_ID_SECURITY);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, ":\n");
            Setting_Wlan_Get_Security_Txt(Ap->security, 20, Txt);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, Txt);

            Label = lv_obj_get_child_back(lv_obj_get_parent(Label), Label);
            lv_label_set_text_id(Label, PHONE_TEXT_ID_SIGNAL_STRENGTH);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, ":\n");
            Hal_Mem_Set(Txt, 0, 20);
            Setting_Wlan_Get_Signal_Txt(Ap->power, 20, Txt);
            lv_label_ins_text(Label, LV_LABEL_POS_LAST, Txt);
            break;
        }
    }
}

static VOID Display_Setting_Wlan_Saved_Ap(hal_wlan_ap_info_t *Ap)
{
    if (NULL == Ap)
    {
        printf("%s: error, ap info lost!\n", __FUNCTION__);
        return;
    }

    UI_Wlan_List_Desc_t *Desc = NULL;
    Nav_Func_List_t     FuncList;
    UINT32              Size;
    UINT8               i = 0;

    Desc = Hal_Mem_Alloc(sizeof(UI_Wlan_List_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Wlan_List_Desc_t));

    Desc->TitleBar.TxtId = LV_LANG_TXT_ID_NONE;
    Desc->TitleBar.TxtAlign = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_CENTER;
    
    Desc->Param = Hal_Mem_Alloc(sizeof(hal_wlan_ap_info_t));
    Hal_Mem_Copy(Desc->Param, Ap, sizeof(hal_wlan_ap_info_t));

    Desc->BtnCnt = 2; // ap information & delete network
    if (HAL_WLAN_SECURITY_OPEN != Ap->security)
    {
        Desc->BtnCnt++; // modify password
    }
    if (HAL_WLAN_AP_STATE_ACT != Ap->state)
    {
        Desc->BtnCnt++; // Connect
    }
    Size = sizeof(UI_Wlan_Btn_Base_Desc_t) * Desc->BtnCnt;
    Desc->BtnList = Hal_Mem_Alloc(Size);
    Hal_Mem_Set(Desc->BtnList, 0, Size);

    Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_STATUS_INFO;
    Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[i].Choise = UI_BASE_OBJ_LABEL;
    Desc->BtnList[i++].u.LabelNum = 3; // status information & security & signal

    Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_DEL_NW;
    Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[i].Choise = UI_BASE_OBJ_NULL;
    Desc->BtnList[i++].RelFunc = Display_Setting_Wlan_Saved_Ap_Del_Nw_Btn_Click_Func;

    if (HAL_WLAN_SECURITY_OPEN != Ap->security)
    {
        Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_MOD_PWD;
        Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
        Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        Desc->BtnList[i].Choise = UI_BASE_OBJ_NULL;
        Desc->BtnList[i++].RelFunc = Display_Setting_Wlan_Saved_Ap_Mod_Pwd_Btn_Click_Func;
    }

    if (HAL_WLAN_AP_STATE_ACT != Ap->state)
    {
        Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_CONNECT;
        Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
        Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        Desc->BtnList[i].Choise = UI_BASE_OBJ_NULL;
        Desc->BtnList[i].RelFunc = Display_Setting_Wlan_Saved_Ap_Conn_Btn_Click_Func;
    }

    Desc->BtnBar.ButtonL.Valid = FALSE;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_List_Com_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Wlan_List_Create;
    FuncList.OnCreate       = Display_Setting_Wlan_Saved_Ap_OnCreate;
    FuncList.OnRestoreState = Display_Setting_Wlan_Saved_Ap_OnCreate;
    FuncList.OnDestroy      = Display_Setting_Wlan_List_Com_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_SAVED_AP, &FuncList, (VOID *)Desc);
}

static VOID Display_Setting_Wlan_Act_Ap_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    Display_Setting_Wlan_Saved_Ap((hal_wlan_ap_info_t *)UI_Get_User_Ptr(Btn));
}

static VOID Display_Setting_Wlan_Saved_Ap_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    hal_wlan_ap_info_t *Ap = (hal_wlan_ap_info_t *)UI_Get_User_Ptr(Btn);
    Display_Setting_Wlan_Saved_Ap(Ap);
}

static VOID Display_Setting_Wlan_Refresh_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    if (hal_wlan_ui_scan_ap())
    {
        UI_Set_User_Num(Btn, UI_WLAN_BTN_TYPE_REFRESHING);
        UI_Wlan_Play_Refreshing_Anim(lv_obj_get_child(lv_obj_get_child(Btn, NULL), NULL),
                                     SYMBOL_REFRESH_2,
                                     Display_Setting_Wlan_Refreshing_Anim_Func);
    }
}

static VOID Display_Setting_Wlan_Non_Saved_Ap_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    hal_wlan_ap_info_t *Ap = UI_Get_User_Ptr(Btn);
    if (NULL == Ap)
    {
        printf("%s: ap info is absent\n", __FUNCTION__);
        return;
    }

    Display_Setting_WLan_Login(Ap);
}

static VOID Display_Setting_Wlan_Refresh_Ui(BOOL SelOpeningBtn)
{
    UI_Wlan_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN);

    if (NULL == Desc)
    {
        return;
    }

    if (SelOpeningBtn)
    {
        Desc->Index = 1;
    }

    if (ACT_ID_SETTING_WLAN != Nav_Get_Top())
    {
        return;
    }

    hal_wlan_info_t *WlanInfo = hal_wlan_get_info();

    if (HAL_WLAN_STATE_OFF == WlanInfo->state)
    {        
        return;
    }

    printf("%s: wlan state %d, SelOpeningBtn %d\n",
           __FUNCTION__, WlanInfo->state, SelOpeningBtn);

    hal_wlan_ap_info_t *Node = NULL;
    UI_Wlan_Btn_Desc_t BtnDesc = {};
    lv_obj_t * Scrl = lv_page_get_scrl(Desc->List);
    lv_obj_t * PrevBtn = lv_obj_get_parent(Desc->Sw.Sw);
    lv_obj_t * RefreshBtn = NULL;
    BOOL RefreshScrl = FALSE;

    Desc->Total = 1;
    BtnDesc.Btn = lv_obj_get_child_back(Scrl, PrevBtn);
    BtnDesc.ApLen = sizeof(hal_wlan_ap_info_t);
    BtnDesc.Par = Desc->List;
    BtnDesc.ImgSrc1 = (VOID *)(SYMBOL_LOCK);
    BtnDesc.AnimFp = Display_Setting_Wlan_Refreshing_Anim_Func;
    if(Desc->RefreshImg) {
        RefreshBtn = lv_obj_get_parent(lv_obj_get_parent(Desc->RefreshImg));
        printf("%s: refresh btn %p, img %p\n", __FUNCTION__, RefreshBtn, Desc->RefreshImg);
    }

    if (WlanInfo->open_ap
        && (0 < strlen(WlanInfo->open_ap->ssid))
        && (HAL_WLAN_MAX_OPEN_TIMES == WlanInfo->open_ap->open_times))
    {
        BtnDesc.Type = UI_WLAN_BTN_TYPE_OPENING;
        BtnDesc.Ssid = WlanInfo->open_ap->ssid;
        if (HAL_WLAN_SECURITY_OPEN == WlanInfo->open_ap->security)
        {
            BtnDesc.IsSecurity = FALSE;
        }
        else
        {
            BtnDesc.IsSecurity = TRUE;
        }
        BtnDesc.ImgSrc2 = (VOID *)(SYMBOL_REFRESH_2);
        BtnDesc.BtnFunc = NULL;
        BtnDesc.Ap = WlanInfo->open_ap;
        if (RefreshBtn == BtnDesc.Btn)
        {
            BtnDesc.Btn = NULL;
            UI_Wlan_Add_Btn(&BtnDesc);
            _lv_ll_move_before(&Scrl->child_ll, BtnDesc.Btn, PrevBtn);
            RefreshScrl = TRUE;
        }
        else
        {
            UI_Wlan_Add_Btn(&BtnDesc);
        }
        Desc->Total++;
        PrevBtn = BtnDesc.Btn;
        BtnDesc.Btn = lv_obj_get_child_back(Scrl, PrevBtn);
    } else if(WlanInfo->act_ap) {
        BtnDesc.Type = UI_WLAN_BTN_TYPE_ACT;
        BtnDesc.Ssid = WlanInfo->act_ap->ssid;
        if (HAL_WLAN_SECURITY_OPEN == WlanInfo->act_ap->security)
        {
            BtnDesc.IsSecurity = FALSE;
        }
        else
        {
            BtnDesc.IsSecurity = TRUE;
        }
        BtnDesc.ImgSrc2 = Display_Setting_Wlan_Get_Signal_Src(WlanInfo->act_ap->power);
        BtnDesc.BtnFunc = Display_Setting_Wlan_Act_Ap_Btn_Click_Func;
        BtnDesc.Ap = WlanInfo->act_ap;
        if (RefreshBtn == BtnDesc.Btn)
        {
            BtnDesc.Btn = NULL;
            UI_Wlan_Add_Btn(&BtnDesc);
            _lv_ll_move_before(&Scrl->child_ll, BtnDesc.Btn, PrevBtn);
            RefreshScrl = TRUE;
        }
        else
        {
            UI_Wlan_Add_Btn(&BtnDesc);
        }
        Desc->Total++;
        PrevBtn = BtnDesc.Btn;
        BtnDesc.Btn = lv_obj_get_child_back(Scrl, PrevBtn);
    }

    Node = _lv_ll_get_head(&WlanInfo->scan_list);
    while (Node)
    {
        if ((HAL_WLAN_AP_STATE_SAVED == Node->state)
            || ((HAL_WLAN_AP_STATE_OPENING == Node->state)
                && (HAL_WLAN_MAX_OPEN_TIMES > Node->open_times)))
        {            
            if (HAL_WLAN_MAX_OPEN_TIMES > Node->open_times)
            {
                BtnDesc.Type = UI_WLAN_BTN_TYPE_OPEN_FAIL;
            }
            else
            {
                BtnDesc.Type = UI_WLAN_BTN_TYPE_SAVED;
            }
            BtnDesc.Ssid = Node->ssid;
            if (HAL_WLAN_SECURITY_OPEN == Node->security)
            {
                BtnDesc.IsSecurity = FALSE;
            }
            else
            {
                BtnDesc.IsSecurity = TRUE;
            }
            BtnDesc.ImgSrc2 = Display_Setting_Wlan_Get_Signal_Src(Node->power);
            BtnDesc.BtnFunc = Display_Setting_Wlan_Saved_Ap_Btn_Click_Func;
            BtnDesc.Ap = Node;
            if (RefreshBtn == BtnDesc.Btn)
            {
                BtnDesc.Btn = NULL;
                UI_Wlan_Add_Btn(&BtnDesc);
                _lv_ll_move_before(&Scrl->child_ll, BtnDesc.Btn, PrevBtn);
                RefreshScrl = TRUE;
            }
            else
            {
                UI_Wlan_Add_Btn(&BtnDesc);
            }
            Desc->Total++;
            PrevBtn = BtnDesc.Btn;
            BtnDesc.Btn = lv_obj_get_child_back(Scrl, PrevBtn);
        }
        Node = _lv_ll_get_next(&WlanInfo->scan_list, Node);
    }

    if(RefreshBtn && (RefreshBtn != BtnDesc.Btn)) {
        while(BtnDesc.Btn) {
            PrevBtn = BtnDesc.Btn;
            BtnDesc.Btn = lv_obj_get_child_back(Scrl, BtnDesc.Btn);
            void * Ptr = UI_Get_User_Ptr(PrevBtn);
            if(Ptr) {
                Hal_Mem_Free(Ptr);
            }
            lv_obj_del(PrevBtn);
            RefreshScrl = FALSE;
            if(RefreshBtn == BtnDesc.Btn) {
                break;
            }
        }
    }

    BtnDesc.Btn = RefreshBtn;
    BtnDesc.Ap = NULL;
    if((HAL_WLAN_STATE_SCAN_AP == WlanInfo->state)
       || (HAL_WLAN_STATE_SCAN_AP == WlanInfo->next_state)
       || ((HAL_WLAN_STATE_OPEN_SPEC_NW == WlanInfo->state)
           && (NULL == WlanInfo->open_ap))) { // refreshing
        BtnDesc.Type = UI_WLAN_BTN_TYPE_REFRESHING;
        BtnDesc.ImgSrc2 = (VOID *)(SYMBOL_REFRESH_2);
        BtnDesc.BtnFunc = NULL;
    } else {
        BtnDesc.Type = UI_WLAN_BTN_TYPE_REFRESH;
        BtnDesc.ImgSrc2 = (VOID *)(SYMBOL_REFRESH_1);
        BtnDesc.BtnFunc = Display_Setting_Wlan_Refresh_Btn_Click_Func;
    }
    UI_Wlan_Add_Btn(&BtnDesc);
    Desc->Total++;
    if (NULL == RefreshBtn)
    {
        RefreshBtn = BtnDesc.Btn;
        Desc->RefreshImg = lv_obj_get_child(lv_obj_get_child(BtnDesc.Btn, NULL), NULL);
        printf("%s: add refresh btn %p, img %p\n", __FUNCTION__, RefreshBtn, Desc->RefreshImg);
    }

    BtnDesc.Btn = lv_obj_get_child_back(Scrl, RefreshBtn);
    Node = _lv_ll_get_head(&WlanInfo->scan_list);
    BtnDesc.Type = UI_WLAN_BTN_TYPE_SCAN_LIST;
    BtnDesc.BtnFunc = Display_Setting_Wlan_Non_Saved_Ap_Btn_Click_Func;
    while (Node)
    {
        if ((HAL_WLAN_AP_STATE_NULL == Node->state) && (0 < strlen(Node->ssid)))
        {
            printf("%s: Btn %p, ssid %s\n", __FUNCTION__, BtnDesc.Btn, Node->ssid);
            BtnDesc.Ssid = Node->ssid;
            if (HAL_WLAN_SECURITY_OPEN == Node->security)
            {
                BtnDesc.IsSecurity = FALSE;
            }
            else
            {
                BtnDesc.IsSecurity = TRUE;
            }
            BtnDesc.ImgSrc2 = Display_Setting_Wlan_Get_Signal_Src(Node->power);
            BtnDesc.Ap = Node;
            UI_Wlan_Add_Btn(&BtnDesc);
            Desc->Total++;
            BtnDesc.Btn = lv_obj_get_child_back(Scrl, BtnDesc.Btn);
        }
        Node = _lv_ll_get_next(&WlanInfo->scan_list, Node);
    }

    while (BtnDesc.Btn)
    {
        PrevBtn = BtnDesc.Btn;
        BtnDesc.Btn = lv_obj_get_child_back(Scrl, BtnDesc.Btn);
        VOID *Ptr = UI_Get_User_Ptr(PrevBtn);
        if (Ptr)
        {
            Hal_Mem_Free(Ptr);
        }
        lv_obj_del(PrevBtn);
        RefreshScrl = FALSE;
    }

    if (RefreshScrl)
    {
        Scrl->signal_cb(Scrl, LV_SIGNAL_CHILD_CHG, NULL);
    }

    if (Desc->Index >= Desc->Total)
    {
        Desc->Index = Desc->Total - 1;
    }

    BtnDesc.Btn = Display_Setting_Wlan_Get_Focus_Btn(Desc);
    lv_list_focus_btn(Desc->List, BtnDesc.Btn);
}

static VOID Display_Setting_Wlan_Info_Chg_Cb(bool Is_Periodic_Scan)
{
    if ((ACT_ID_SETTING_WLAN == Nav_Get_Top()) && (TRUE == Framework_Get_Lcd_Status()))
    {
        if (Is_Periodic_Scan)
        {
#ifdef BUILD_IN_PC_SIMULATOR
            Mmi_Wlan_Periodic_Scan_Start_Ind();
#else
            UI_Send_Inter_Msg(UI_SUB_MODULE_COMMON_UI, MMI_WLAN_PERIODIC_SCAN_START_IND, NULL);
#endif
        }
        else
        {
#ifdef BUILD_IN_PC_SIMULATOR
            Mmi_Wlan_Refresh_Ind();
#else
            UI_Send_Inter_Msg(UI_SUB_MODULE_COMMON_UI, MMI_WLAN_REFRESH_IND, NULL);
#endif
        }
    }
}

static UINT8 Display_Setting_Wlan_Del_Saved_Nw_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta,
                                                      UI_KEY_VALUE Key_Val)
{
    UINT8 Ret = 1; // not call default key function for List

    if (KEY_RELEASED != Key_Sta)
    {
        return(0);
    }

    if (KEY_SOFTRIGHT == Key_Val)
    {
        Nav_Back(ACT_ID_ANY);
    }
    else if (KEY_END == Key_Val)
    {
        Nav_Home(ACT_ID_ANY);
    }
    else if (KEY_OK == Key_Val)
    {
        UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_DEL_SAVED_NW);

        /* refresh ACT_ID_SETTING_WLAN_SAVED_NW */
        UI_Normal_List_Only_Desc_t *SavedNwDesc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SAVED_NW);
        SavedNwDesc->List.ListButtonCnt--;
        SavedNwDesc->List.ButtonList = NULL;
        SavedNwDesc->List.Index = 0;
        Hal_Mem_Free(SavedNwDesc->List.ButtonList);
        hal_wlan_saved_nw_t *Nw = (hal_wlan_saved_nw_t *)Desc->Param;
        hal_wlan_ui_del_saved_nw(Nw->ssid, Nw->security);
        if (0 < SavedNwDesc->List.ListButtonCnt)
        {
            UINT32 Len = sizeof(UI_Button_Desc_t) * SavedNwDesc->List.ListButtonCnt;
            SavedNwDesc->List.ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(Len);
            Hal_Mem_Set(SavedNwDesc->List.ButtonList, 0, Len);
            hal_wlan_info_t *WlanInfo = hal_wlan_get_info();
            hal_wlan_saved_nw_t *Node = _lv_ll_get_head(&WlanInfo->save_list);
            UINT8 i = 0;
            while (Node)
            {
                SavedNwDesc->List.ButtonList[i].Valid       = TRUE;
                SavedNwDesc->List.ButtonList[i].TxtId       = LV_LANG_TXT_ID_NONE;
                SavedNwDesc->List.ButtonList[i].ButtonIndex = i;
                SavedNwDesc->List.ButtonList[i].BtnTxt      = Node->ssid;
                SavedNwDesc->List.ButtonList[i].ReleaseFun
                    = Display_Setting_Wlan_Saved_Nw_Btn_Click_Func;
                i++;
                Node = _lv_ll_get_next(&WlanInfo->save_list, Node);
            }
        }

        Nav_Back(ACT_ID_ANY);
    }
    else if ((KEY_LEFT != Key_Val)
             && (KEY_RIGHT != Key_Val)
             && (KEY_UP != Key_Val)
             && (KEY_DOWN != Key_Val))
    {
        Ret = 0;
    }

    return(Ret);
}

static VOID Display_Setting_Wlan_Del_Saved_Nw_OnCreate(VOID *Param)
{
    UI_Wlan_List_Desc_t *Desc   = (UI_Wlan_List_Desc_t *)Param;
    hal_wlan_saved_nw_t  *Nw     = (hal_wlan_saved_nw_t *)Desc->Param;
    INT8                Txt[20] = {};

    lv_label_ins_text(Desc->BtnList[0].Label.Label, LV_LABEL_POS_LAST, ":\n");
    lv_label_ins_text(Desc->BtnList[0].Label.Label, LV_LABEL_POS_LAST, Nw->ssid);

    lv_label_ins_text(Desc->BtnList[1].Label.Label, LV_LABEL_POS_LAST, ":\n");
    Setting_Wlan_Get_Security_Txt(Nw->security, 20, Txt);
    lv_label_ins_text(Desc->BtnList[1].Label.Label, LV_LABEL_POS_LAST, Txt);
}

static VOID Display_Setting_Wlan_Del_Saved_Nw(hal_wlan_saved_nw_t *Nw)
{
    UI_Wlan_List_Desc_t *Desc;
    Nav_Func_List_t     FuncList;
    UINT32              Size;

    Desc = Hal_Mem_Alloc(sizeof(UI_Wlan_List_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Wlan_List_Desc_t));

    Desc->TitleBar.TxtId      = PHONE_TEXT_ID_DEL_NW;
    Desc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    Desc->Param = Hal_Mem_Alloc(sizeof(hal_wlan_saved_nw_t));
    Hal_Mem_Copy(Desc->Param, Nw, sizeof(hal_wlan_saved_nw_t));

    Desc->BtnCnt = 2;
    Desc->Index = Desc->BtnCnt; // not select the btn
    Size = sizeof(UI_Wlan_Btn_Base_Desc_t) * Desc->BtnCnt;
    Desc->BtnList = Hal_Mem_Alloc(Size);
    Hal_Mem_Set(Desc->BtnList, 0, Size);

    Desc->BtnList[0].Label.TxtId = PHONE_TEXT_ID_SSID;
    Desc->BtnList[0].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[0].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[0].Choise = UI_BASE_OBJ_NULL;

    Desc->BtnList[1].Label.TxtId = PHONE_TEXT_ID_SECURITY;
    Desc->BtnList[1].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[1].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[1].Choise = UI_BASE_OBJ_NULL;

    Desc->BtnBar.ButtonL.Valid = FALSE;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_Del_Saved_Nw_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Wlan_List_Create;
    FuncList.OnCreate       = Display_Setting_Wlan_Del_Saved_Nw_OnCreate;
    FuncList.OnRestoreState = Display_Setting_Wlan_Del_Saved_Nw_OnCreate;
    FuncList.OnDestroy      = Display_Setting_Wlan_List_Com_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_DEL_SAVED_NW, &FuncList, Desc);
}

static VOID Display_Setting_Wlan_Saved_Nw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    Display_Setting_Wlan_Del_Saved_Nw((hal_wlan_saved_nw_t *)UI_Get_User_Ptr(Btn));
}

static UINT8 Display_Setting_Wlan_Saved_Nw_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta,
                                                  UI_KEY_VALUE Key_Val)
{
    UINT8 Ret = 0; // call default key function for List

    if (KEY_RELEASED != Key_Sta)
    {
        return(Ret);
    }

    UI_Normal_List_Only_Desc_t *Desc;

    switch (Key_Val)
    {
    case KEY_SOFTRIGHT:
        Nav_Back(ACT_ID_ANY);
        Ret = 1;
        break;

    case KEY_END:
        Nav_Home(ACT_ID_ANY);
        Ret = 1;
        break;

    case KEY_UP:
    case KEY_LEFT:
        Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SAVED_NW);
        if (0 == Desc->List.ListButtonCnt)
        {
            Ret = 1;
            break;
        }

        if (0 < Desc->List.Index)
        {
            Desc->List.Index--;
        }
        else
        {
            Desc->List.Index = Desc->List.ListButtonCnt - 1;
        }
        break;

    case KEY_DOWN:
    case KEY_RIGHT:
        Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SAVED_NW);
        if (0 == Desc->List.ListButtonCnt)
        {
            Ret = 1;
            break;
        }

        if ((Desc->List.ListButtonCnt - 1) != Desc->List.Index)
        {
            Desc->List.Index++;
        }
        else
        {
            Desc->List.Index = 0;
        }
        break;

    case KEY_OK:
        Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SAVED_NW);
        if (0 == Desc->List.ListButtonCnt)
        {
            Ret = 1;
        }
        break;

    default:
        break;
    } /* switch */

    return(Ret);
}

static VOID Display_Setting_Wlan_Saved_Nw_OnCreate(VOID *Param)
{
    UI_Normal_List_Only_Desc_t *Desc = (UI_Normal_List_Only_Desc_t *)Param;
    if (0 == Desc->List.ListButtonCnt)
    {
        lv_obj_t *Label = lv_label_create(Desc->List.List, NULL);
        lv_label_set_text_id(Label, PHONE_TEXT_ID_EMPTY);
        lv_obj_add_protect(Label, LV_PROTECT_POS);
        lv_obj_align(Label, Desc->List.List, LV_ALIGN_CENTER, 0, 0);
    }
    else
    {
        hal_wlan_info_t *WlanInfo = hal_wlan_get_info();
        hal_wlan_saved_nw_t *Node = _lv_ll_get_head(&WlanInfo->save_list);
        UINT8 i = 0;
        while (Node)
        {
            UI_Set_User_Ptr(Desc->List.ButtonList[i].Button, Node);
            i++;
            Node = _lv_ll_get_next(&WlanInfo->save_list, Node);
        }
    }
}

static VOID Display_Setting_Wlan_Saved_Nw_OnDestroy(VOID *Param)
{
    UI_Normal_List_Only_Desc_t *Desc = (UI_Normal_List_Only_Desc_t *)Param;
    if (Desc->List.ButtonList)
    {
        // not free BtnTxt
        Hal_Mem_Free(Desc->List.ButtonList);
    }
    Hal_Mem_Free(Param);
}

static VOID Display_Setting_Wlan_Saved_Nw(VOID)
{
    UI_Normal_List_Only_Desc_t *Desc;
    Nav_Func_List_t            FuncList;
    UINT32                     Len;

    Desc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    Desc->TitleBar.TxtId      = PHONE_TEXT_ID_SAVED_NW;
    Desc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    hal_wlan_info_t *WlanInfo = hal_wlan_get_info();
    hal_wlan_saved_nw_t *Node = _lv_ll_get_head(&WlanInfo->save_list);
    while (Node)
    {
        Desc->List.ListButtonCnt++;
        Node = _lv_ll_get_next(&WlanInfo->save_list, Node);
    }
    if (0 < Desc->List.ListButtonCnt)
    {
        Len = sizeof(UI_Button_Desc_t) * Desc->List.ListButtonCnt;
        Desc->List.ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(Len);
        Hal_Mem_Set(Desc->List.ButtonList, 0, Len);
        Node = _lv_ll_get_head(&WlanInfo->save_list);
        UINT8 i = 0;
        while (Node)
        {
            Desc->List.ButtonList[i].Valid       = TRUE;
            Desc->List.ButtonList[i].TxtId       = LV_LANG_TXT_ID_NONE;
            Desc->List.ButtonList[i].ButtonIndex = i;
            Desc->List.ButtonList[i].BtnTxt      = Node->ssid;
            Desc->List.ButtonList[i].ReleaseFun  = Display_Setting_Wlan_Saved_Nw_Btn_Click_Func;
            i++;
            Node = _lv_ll_get_next(&WlanInfo->save_list, Node);
        }
    }

    Desc->BtnBar.ButtonL.Valid = FALSE;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_Saved_Nw_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_List_Only_Create;
    FuncList.OnCreate       = Display_Setting_Wlan_Saved_Nw_OnCreate;
    FuncList.OnRestoreState = Display_Setting_Wlan_Saved_Nw_OnCreate;
    FuncList.OnDestroy      = Display_Setting_Wlan_Saved_Nw_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_SAVED_NW, &FuncList, Desc);
}

static UINT8 Display_Setting_Wlan_Sel_Security_Key_Cb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta,
                                                      UI_KEY_VALUE Key_Val)
{
    UINT8 Ret = 0; // call default key function for List

    if (KEY_RELEASED != Key_Sta)
    {
        return(Ret);
    }

    UI_Normal_List_Only_Desc_t *Desc;

    switch (Key_Val)
    {
    case KEY_SOFTRIGHT:
        Nav_Back(ACT_ID_ANY);
        Ret = 1;
        break;

    case KEY_END:
        Nav_Home(ACT_ID_ANY);
        Ret = 1;
        break;

    case KEY_UP:
    case KEY_LEFT:
        Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SEL_SECURITY);
        if (0 < Desc->List.Index)
        {
            Desc->List.Index--;
        }
        else
        {
            Desc->List.Index = Desc->List.ListButtonCnt - 1;
        }
        break;

    case KEY_DOWN:
    case KEY_RIGHT:
        Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SEL_SECURITY);
        if ((Desc->List.ListButtonCnt - 1) != Desc->List.Index)
        {
            Desc->List.Index++;
        }
        else
        {
            Desc->List.Index = 0;
        }
        break;

    default:
        break;
    } /* switch */

    return(Ret);
}

static VOID Display_Setting_Wlan_Sel_Security_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Normal_List_Only_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_SEL_SECURITY);
    UI_Wlan_List_Desc_t *AddNwDesc = Nav_Get_Param(ACT_ID_SETTING_WLAN_ADD_NW);
    HAL_WLAN_SECURITY_T *Security = (HAL_WLAN_SECURITY_T *)AddNwDesc->Param;
    *Security = Desc->List.ButtonList[Desc->List.Index].ButtonIndex;
    Nav_Back(ACT_ID_ANY);
}

static VOID Display_Setting_Wlan_Sel_Security_OnDestroy(VOID *Param)
{
    UI_Normal_List_Only_Desc_t *Desc = (UI_Normal_List_Only_Desc_t *)Param;
    UINT8 i;
    for (i = 0;i < Desc->List.ListButtonCnt;i++)
    {
        Hal_Mem_Free(Desc->List.ButtonList[i].BtnTxt);
    }
    Hal_Mem_Free(Desc->List.ButtonList);
    Hal_Mem_Free(Param);
}

static VOID Display_Setting_WLan_Sel_Security(HAL_WLAN_SECURITY_T Security)
{
    UI_Normal_List_Only_Desc_t *Desc;
    Nav_Func_List_t            FuncList;
    UINT32                     Len;
    HAL_WLAN_SECURITY_T        i;
    UINT8                      j = 0;

    Desc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    Desc->TitleBar.TxtId      = PHONE_TEXT_ID_SECURITY;
    Desc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    Desc->List.ListButtonCnt = HAL_WLAN_SECURITY_MAX;
    Len = sizeof(UI_Button_Desc_t) * Desc->List.ListButtonCnt;
    Desc->List.ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(Len);
    Hal_Mem_Set(Desc->List.ButtonList, 0, Len);

    Desc->List.Index = Security - HAL_WLAN_SECURITY_OPEN;

    for (i = HAL_WLAN_SECURITY_OPEN;i < HAL_WLAN_SECURITY_MAX;i++)
    {
        Desc->List.ButtonList[j].Valid       = TRUE;
        Desc->List.ButtonList[j].TxtId       = LV_LANG_TXT_ID_NONE;
        Desc->List.ButtonList[j].ButtonIndex = i;
        Desc->List.ButtonList[j].BtnTxt      = Hal_Mem_Alloc(20);
        Setting_Wlan_Get_Security_Txt(i, 20, Desc->List.ButtonList[j].BtnTxt);
        Desc->List.ButtonList[i].ReleaseFun  = Display_Setting_Wlan_Sel_Security_Btn_Click_Func;
        j++;
    }

    Desc->BtnBar.ButtonL.Valid = FALSE;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_Sel_Security_Key_Cb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_List_Only_Create;
    FuncList.OnDestroy = Display_Setting_Wlan_Sel_Security_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_SEL_SECURITY, &FuncList, Desc);
}

static VOID Display_Setting_Wlan_Add_Nw_Security_Btn_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_ADD_NW);
    Display_Setting_WLan_Sel_Security(*((HAL_WLAN_SECURITY_T *)Desc->Param));
}

static VOID Display_Setting_WLan_Add_Nw_Save_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Wlan_List_Desc_t *Desc    = Nav_Get_Param(ACT_ID_SETTING_WLAN_ADD_NW);
    HAL_WLAN_SECURITY_T Security = *((HAL_WLAN_SECURITY_T *)Desc->Param);
    INT8                *Ssid    = NULL;
    INT8                *Pwd     = NULL;
    hal_wlan_saved_nw_t nw       = {};
    UINT8               i;
    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if (PHONE_TEXT_ID_SSID == Desc->BtnList[i].Label.TxtId)
        {
            Ssid = (INT8 *)lv_textarea_get_text(Desc->BtnList[i].u.Ta.TextArea);
            if (HAL_WLAN_SECURITY_OPEN == Security)
            {
                break;
            }
        }
        else if (PHONE_TEXT_ID_PWD == Desc->BtnList[i].Label.TxtId)
        {
            Pwd = (INT8 *)lv_textarea_get_text(Desc->BtnList[i].u.Ta.TextArea);
        }
    }
    printf("%s: sec %d, ssid %s, pwd %s\n", __FUNCTION__, Security, Ssid, Pwd);
    if ((NULL == Ssid) || (Ssid && (0 == strlen(Ssid))))
    {
        Display_Setting_Wlan_Status(PHONE_TEXT_ID_NO_SSID);
        return;
    }

    if (Pwd && (HAL_WLAN_MIN_PWD_LEN > strlen(Pwd)))
    {
        Display_Setting_Wlan_Status(PHONE_TEXT_ID_MIN_PWD_LEN_IS_8);
        return;
    }

    strncpy(nw.ssid, Ssid, HAL_WLAN_MAX_SSID_LEN + 1);
    nw.security = Security;
    if (Pwd)
    {
        strncpy(nw.pwd, Pwd, HAL_WLAN_MAX_PWD_LEN + 1);
    }
    if (hal_wlan_ui_add_nw(&nw))
    {
        Display_Setting_Wlan_Refresh_Ui(TRUE);
    }
    Nav_Back(ACT_ID_ANY);
}

static VOID Display_Setting_Wlan_Add_Nw_OnCreate(VOID *Param)
{
    UI_Wlan_List_Desc_t *Desc = (UI_Wlan_List_Desc_t *)Param;
    HAL_WLAN_SECURITY_T Security = *((HAL_WLAN_SECURITY_T *)Desc->Param);
    INT8 SecurityTxt[20] = {};
    UINT8 i;

    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if (PHONE_TEXT_ID_SSID == Desc->BtnList[i].Label.TxtId)
        {
            lv_textarea_set_max_length(Desc->BtnList[i].u.Ta.TextArea, HAL_WLAN_MAX_SSID_LEN);
            if (Desc->BtnList[i].u.Ta.TaTxt)
            {
                Hal_Mem_Free(Desc->BtnList[i].u.Ta.TaTxt);
                Desc->BtnList[i].u.Ta.TaTxt = NULL;
            }
        }
        else if (PHONE_TEXT_ID_SECURITY == Desc->BtnList[i].Label.TxtId)
        {
            UI_Set_User_Num(Desc->BtnList[i].Btn, Security);   
            Setting_Wlan_Get_Security_Txt(Security, 20, SecurityTxt);
            lv_textarea_set_text(Desc->BtnList[i].u.Ta.TextArea, SecurityTxt);
        }
        else if (PHONE_TEXT_ID_PWD == Desc->BtnList[i].Label.TxtId)
        {
            lv_textarea_set_max_length(Desc->BtnList[i].u.Ta.TextArea, HAL_WLAN_MAX_PWD_LEN);
            if (Desc->BtnList[i].u.Ta.TaTxt)
            {
                Hal_Mem_Free(Desc->BtnList[i].u.Ta.TaTxt);
                Desc->BtnList[i].u.Ta.TaTxt = NULL;
            }
            if (HAL_WLAN_SECURITY_OPEN == Security)
            {
                lv_obj_set_hidden(Desc->BtnList[i].Btn, TRUE);
            }
        }
    }
}

static VOID Display_Setting_Wlan_Add_Nw(VOID)
{
    UI_Wlan_List_Desc_t *Desc = NULL;
    Nav_Func_List_t     FuncList;
    UINT32              Size;
    HAL_WLAN_SECURITY_T *Security;

    Desc = Hal_Mem_Alloc(sizeof(UI_Wlan_List_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Wlan_List_Desc_t));

    Desc->TitleBar.TxtId = PHONE_TEXT_ID_ADD_NW;
    Desc->TitleBar.TxtAlign = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_CENTER;

    Desc->BtnCnt = 3;
    Size = sizeof(UI_Wlan_Btn_Base_Desc_t) * Desc->BtnCnt;
    Desc->BtnList = Hal_Mem_Alloc(Size);
    Hal_Mem_Set(Desc->BtnList, 0, Size);

    Security = Hal_Mem_Alloc(sizeof(HAL_WLAN_SECURITY_T));
    *Security = HAL_WLAN_SECURITY_OPEN;
    Desc->Param = (VOID *)Security;

    Desc->BtnList[0].Label.TxtId = PHONE_TEXT_ID_SSID;
    Desc->BtnList[0].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[0].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[0].Choise = UI_BASE_OBJ_TA;
    Desc->BtnList[0].u.Ta.TaCursorHide = TRUE;
    Desc->BtnList[0].RelFunc = Display_Setting_WLan_List_Input_Btn_Com_Func;

    Desc->BtnList[1].Label.TxtId = PHONE_TEXT_ID_SECURITY;
    Desc->BtnList[1].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[1].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[1].Choise = UI_BASE_OBJ_TA;
    Desc->BtnList[1].u.Ta.TaCursorHide = TRUE;
    Desc->BtnList[1].RelFunc = Display_Setting_Wlan_Add_Nw_Security_Btn_Func;

    Desc->BtnList[2].Label.TxtId = PHONE_TEXT_ID_PWD;
    Desc->BtnList[2].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[2].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[2].Choise = UI_BASE_OBJ_TA;
    Desc->BtnList[2].u.Ta.TaCursorHide = TRUE;
    Desc->BtnList[2].RelFunc = Display_Setting_WLan_List_Input_Btn_Com_Func;

    Desc->BtnBar.ButtonL.Valid      = TRUE;
    Desc->BtnBar.ButtonL.TxtId      = PHONE_TEXT_ID_SAVE;
    Desc->BtnBar.ButtonL.ReleaseFun = Display_Setting_WLan_Add_Nw_Save_Btn_Click_Func;
    Desc->BtnBar.ButtonM.Valid      = TRUE;
    Desc->BtnBar.ButtonM.TxtId      = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid      = TRUE;
    Desc->BtnBar.ButtonR.TxtId      = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_List_Com_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Wlan_List_Create;
    FuncList.OnCreate       = Display_Setting_Wlan_Add_Nw_OnCreate;
    FuncList.OnRestoreState = Display_Setting_Wlan_Add_Nw_OnCreate;
    FuncList.OnSaveState    = Display_Setting_Wlan_List_Com_OnSave;
    FuncList.OnDestroy      = Display_Setting_Wlan_List_Com_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_ADD_NW, &FuncList, Desc);
}

static VOID Display_Setting_Wlan_Opt_Auto_Sel_Nw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    UI_Wlan_List_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN_OPT);
    UINT8 i;
    for (i = 0;i < Desc->BtnCnt;i++)
    {
        if (Btn == Desc->BtnList[i].Btn)
        {
            if (Desc->BtnList[i].u.Sw.State)
            {
                Desc->BtnList[i].u.Sw.State = FALSE;
                lv_switch_off(Desc->BtnList[i].u.Sw.Sw, FALSE);
            }
            else
            {
                Desc->BtnList[i].u.Sw.State = TRUE;
                lv_switch_on(Desc->BtnList[i].u.Sw.Sw, FALSE);
            }
            if(hal_wlan_ui_set_auto_sel_nw(Desc->BtnList[i].u.Sw.State)) {
                Display_Setting_Wlan_Refresh_Ui(FALSE);
            }
            break;
        }
    }
}

static VOID Display_Setting_Wlan_Opt_Saved_Nw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    Display_Setting_Wlan_Saved_Nw();
}

static VOID Display_Setting_Wlan_Opt_Add_Nw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    Display_Setting_Wlan_Add_Nw();
}

static VOID Display_Setting_Wlan_Opt(VOID)
{
    UI_Wlan_List_Desc_t *Desc;
    Nav_Func_List_t     FuncList;
    UINT32              Len;
    hal_wlan_info_t     *WlanInfo = hal_wlan_get_info();
    UINT8               i = 0;

    Desc = Hal_Mem_Alloc(sizeof(UI_Wlan_List_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Wlan_List_Desc_t));

    Desc->TitleBar.TxtId      = PHONE_TEXT_ID_SETTINGS;
    Desc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    Desc->BtnCnt = 1; // saved nw
    if (HAL_WLAN_STATE_OFF != WlanInfo->state)
    {
        Desc->BtnCnt += 2; // add nw & auto set
    }
    Len = sizeof(UI_Wlan_Btn_Base_Desc_t) * Desc->BtnCnt;
    Desc->BtnList = Hal_Mem_Alloc(Len);
    Hal_Mem_Set(Desc->BtnList, 0, Len);

    Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_SAVED_NW;
    Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
    Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    Desc->BtnList[i].Choise = UI_BASE_OBJ_NULL;
    Desc->BtnList[i++].RelFunc = Display_Setting_Wlan_Opt_Saved_Nw_Btn_Click_Func;

    if (HAL_WLAN_STATE_OFF != WlanInfo->state)
    {
        Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_ADD_NW;
        Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
        Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        Desc->BtnList[i].Choise = UI_BASE_OBJ_NULL;
        Desc->BtnList[i++].RelFunc = Display_Setting_Wlan_Opt_Add_Nw_Btn_Click_Func;

        Desc->BtnList[i].Label.TxtId = PHONE_TEXT_ID_AUTO_SEL_NW;
        Desc->BtnList[i].Label.TxtAlign = LV_LABEL_ALIGN_LEFT;
        Desc->BtnList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        Desc->BtnList[i].Choise = UI_BASE_OBJ_SW;
        Desc->BtnList[i].RelFunc = Display_Setting_Wlan_Opt_Auto_Sel_Nw_Btn_Click_Func;
        Desc->BtnList[i].u.Sw.State = WlanInfo->is_auto_sel_nw;
    }

    Desc->BtnBar.ButtonL.Valid = FALSE;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_List_Com_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Wlan_List_Create;
    FuncList.OnDestroy = Display_Setting_Wlan_List_Com_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN_OPT, &FuncList, Desc);
}

/**
 * Handle key for Setting_Wlan
 * param (in) Obj: lv_obj_t*
 *       (in) Key_Sta: UI_KEY_STATUS
 *       (in) Key_Val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Wlan_KeyCb(lv_obj_t *Obj, UI_KEY_STATUS Key_Sta, UI_KEY_VALUE Key_Val)
{
    UINT8 Ret = 1;
    if (KEY_RELEASED != Key_Sta)
    {
        return(0);
    }

    UI_Wlan_Desc_t *Desc;
    lv_obj_t *Btn;

    if ((KEY_DOWN == Key_Val) || (KEY_UP == Key_Val))
    {
        Desc = (UI_Wlan_Desc_t *)Nav_Get_Param(ACT_ID_SETTING_WLAN);
        if (1 < Desc->Total)
        {
            if (KEY_DOWN == Key_Val)
            {
                Desc->Index++;
                Desc->Index %= Desc->Total;
            }
            else
            {
                Desc->Index += Desc->Total;
                Desc->Index--;
                Desc->Index %= Desc->Total;
            }
            Btn = Display_Setting_Wlan_Get_Focus_Btn(Desc);
            lv_list_focus_btn(Desc->List, Btn);
        }
    }
    else if (KEY_OK == Key_Val)
    {
        Desc = (UI_Wlan_Desc_t *)Nav_Get_Param(ACT_ID_SETTING_WLAN);
        Btn = lv_list_get_btn_selected(Desc->List);
        lv_event_cb_t RelFunc = lv_obj_get_event_cb(Btn);
        if (RelFunc)
        {
            RelFunc(Btn, LV_EVENT_CLICKED);
        }
    }
    else if (KEY_SOFTLEFT == Key_Val)
    {
        Display_Setting_Wlan_Opt();
    }
    else if (KEY_SOFTRIGHT == Key_Val)
    {
        Nav_Back(ACT_ID_ANY);
    }
    else if (KEY_END == Key_Val)
    {
        Nav_Home(ACT_ID_ANY);
    }
    else
    {
        Ret = 0;
    }

    return(Ret);
}

static VOID Setting_Wlan_Rm_Ap_List_Btn(UI_Wlan_Desc_t *Desc)
{
    printf("%s\n", __FUNCTION__);
    lv_obj_t *Scrl = lv_page_get_scrl(Desc->List);
    lv_obj_t *SwBtn = lv_obj_get_parent(Desc->Sw.Sw);
    lv_obj_t *Btn = lv_obj_get_child_back(Scrl, SwBtn);
    lv_obj_t *BtnPrev;
    VOID *Ptr;
    while (Btn)
    {
        BtnPrev = lv_obj_get_child_back(Scrl, Btn);
        Ptr = UI_Get_User_Ptr(Btn);
        if (Ptr)
        {
            Hal_Mem_Free(Ptr);
        }
        lv_obj_del(Btn);
        Btn = BtnPrev;
    }
    Desc->Total = 1;
    Desc->Index = 0;
    lv_list_focus_btn(Desc->List, SwBtn);
    Desc->RefreshImg = NULL;
}

static VOID Setting_Wlan_Add_Note(lv_obj_t *Par)
{
    lv_obj_t *NoteLabel = lv_label_create(Par, NULL);
    lv_label_set_align(NoteLabel, LV_LABEL_ALIGN_CENTER);
    lv_label_set_long_mode(NoteLabel, LV_LABEL_LONG_BREAK);
    lv_obj_set_width(NoteLabel, lv_obj_get_width(Par) - 40);
    lv_label_set_text_id(NoteLabel, PHONE_TEXT_ID_WLAN_NOTE);
    lv_obj_add_protect(NoteLabel, LV_PROTECT_POS);
    lv_obj_align(NoteLabel, Par, LV_ALIGN_CENTER, 0, 0);
}

static VOID Display_Setting_Wlan_Sw_Btn_Click_Func(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED != Event)
    {
        return;
    }

    hal_wlan_info_t *WlanInfo = hal_wlan_get_info();

    printf("%s: wlan_state %d\n", __FUNCTION__, WlanInfo->state);
    UI_Wlan_Desc_t *Desc = Nav_Get_Param(ACT_ID_SETTING_WLAN);
    if(HAL_WLAN_STATE_OFF != WlanInfo->state) {
        if (hal_wlan_ui_close_wlan(FALSE))
        {
            Desc->Sw.State = FALSE;
            lv_switch_off(Desc->Sw.Sw, FALSE);
            lv_label_set_text_id(lv_obj_get_child_back(Btn, NULL), PHONE_TEXT_ID_WLAN_OFF);
            Setting_Wlan_Rm_Ap_List_Btn(Desc);
            Setting_Wlan_Add_Note(lv_obj_get_parent(Desc->List));
        }
    } else {
        if (hal_wlan_ui_start_wlan(FALSE))
        {
            Desc->Sw.State = TRUE;
            lv_switch_on(Desc->Sw.Sw, FALSE);
            lv_label_set_text_id(lv_obj_get_child_back(Btn, NULL), PHONE_TEXT_ID_WLAN_ON);
            lv_obj_del(lv_obj_get_child(lv_obj_get_parent(Desc->List), NULL));
            Display_Setting_Wlan_Refresh_Ui(FALSE);
        }
    }
}

static VOID Display_Setting_Wlan_OnCreate(VOID *Param)
{
    UI_Wlan_Desc_t *Desc = (UI_Wlan_Desc_t *)Param;
    if (Desc->Sw.State)
    {
        Display_Setting_Wlan_Refresh_Ui(FALSE);
    }
    else
    {
        Setting_Wlan_Add_Note(lv_obj_get_parent(Desc->List));
        lv_list_focus_btn(Desc->List, lv_obj_get_parent(Desc->Sw.Sw));
    }
}

static VOID Display_Setting_Wlan_OnSave(VOID *Param)
{
    UI_Wlan_Desc_t *Desc = (UI_Wlan_Desc_t *)Param;
    Desc->RefreshImg = NULL;
}

static VOID Display_Setting_Wlan_OnDestroy(VOID *Param)
{
    if (ACT_ID_SETTING_WLAN == Nav_Get_Top())
    {
        Setting_Wlan_Rm_Ap_List_Btn((UI_Wlan_Desc_t *)Param);
    }
    hal_wlan_ui_state_chg(FALSE);
    Hal_Mem_Free(Param);
}

/**
 * Display Setting_Wlan
 * param (in) VOID:
 * return VOID:
 */
static VOID Display_Setting_Wlan(VOID)
{
    hal_wlan_ui_state_chg(TRUE);

    UI_Wlan_Desc_t  *Desc = NULL;
    Nav_Func_List_t FuncList;

    Desc = (UI_Wlan_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Wlan_Desc_t));
    Hal_Mem_Set(Desc, 0, sizeof(UI_Wlan_Desc_t));

    Desc->TitleBar.TxtId      = PHONE_TEXT_ID_WLAN;
    Desc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    Desc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    hal_wlan_info_t *WlanInfo = hal_wlan_get_info();
    printf("%s: wlan state %d\n", __FUNCTION__, WlanInfo->state);
    if (HAL_WLAN_STATE_OFF == WlanInfo->state)
    {
        Desc->Sw.State = FALSE;
    }
    else
    {
        Desc->Sw.State = TRUE;
    }
    Desc->Sw.BtnFunc = Display_Setting_Wlan_Sw_Btn_Click_Func;

    Desc->BtnBar.ButtonL.Valid = TRUE;
    Desc->BtnBar.ButtonL.TxtId = PHONE_TEXT_ID_OPT;
    Desc->BtnBar.ButtonM.Valid = TRUE;
    Desc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    Desc->BtnBar.ButtonR.Valid = TRUE;
    Desc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    Desc->KeyFunc = Display_Setting_Wlan_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Wlan_Create;
    FuncList.OnCreate       = Display_Setting_Wlan_OnCreate;
    FuncList.OnRestoreState = Display_Setting_Wlan_OnCreate;
    FuncList.OnSaveState    = Display_Setting_Wlan_OnSave;
    FuncList.OnDestroy      = Display_Setting_Wlan_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_SETTING_WLAN, &FuncList, (VOID *)Desc);
}

#endif
